package homework.view;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import homework.service.Usermanage;

public class C2Frame extends JFrame{
	
	private JLabel l_name,l_id,l_username,l_logisticslist;
    private JTextField t_id, t_username,t_logisticslist;
    private JButton b_send, b_reset;
    
	public C2Frame(){
    	
        this.setTitle("快递物流平台-后台投递页面(C2)");
        setSize(400,500);
    	setLocation(800,200);;
        init();
        this.setVisible(true);

	}
	public void init(){
        this.setLayout(null);
        
        Font font = new Font("宋体", Font.PLAIN, 30);
        l_name = new JLabel("包裹登记");
        l_name.setFont(font);
	    
	    l_id = new JLabel("编号",(int)CENTER_ALIGNMENT);
	    t_id = new JTextField();
	    l_username = new JLabel("寄件人(用户名)",(int)CENTER_ALIGNMENT);
	    t_username = new JTextField();
	    l_logisticslist = new JLabel("物流更新信息",(int)CENTER_ALIGNMENT);
	    t_logisticslist = new JTextField();
	    
	    b_reset = new JButton("重置");
	    b_reset.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				t_id.setText("");
				t_username.setText("");
				t_logisticslist.setText("");
			}
		});
	    b_send = new JButton("登记");
	    b_send.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO 自动生成的方法存根
				String s2;
				Usermanage um = new Usermanage();
				int f = um.packageadd(t_username.getText(),t_id.getText(), t_logisticslist.getText());
				if(f==1) {
					JOptionPane.showMessageDialog(null, "操作成功");
				}
				
			}
		});
	    JPanel p= new JPanel(new GridLayout(1,1,5,5));
	    p.add(l_name);
	    add(p);
	    
	    p= new JPanel(new GridLayout(4,2,5,5));
	    p.add(l_id);
    	p.add(t_id);
    	p.add(l_username);
    	p.add(t_username);
    	p.add(l_logisticslist);
    	p.add(t_logisticslist);
    	p.add(b_reset);
    	p.add(b_send);
    	p.setBounds(5,5,390,200);
    	add(p);
	}

}
